import React, { Component } from 'react'
import './index.scss'
import { Form, Input, Button } from 'antd';
export default class login extends Component {


  render() {
    const onFinish = (values) => {
      // console.log('Success:', values);
      this.$axios.post(this.$urls.login,{
        username:values.username,
        password:values.password
      }).then(res=>{
        if (res.code===20000) {
          sessionStorage.setItem('userInfo',JSON.stringify(res.data))
          sessionStorage.setItem('accessToken',res.data.token)
          this.props.history.replace('/statistics')
          // console.log(this,'============');
        }
      }).catch(err=>{
        console.log(err)
      })
    };

    const onFinishFailed = (errorInfo) => {
      console.log('Failed:', errorInfo);
    };

    return (
      <div className="content login">
        <div className="login_box">
          <Form
            name="basic"
            labelCol={{ span: 6 }}
            onFinish={onFinish}
            onFinishFailed={onFinishFailed}
          >
            <Form.Item
              label="用户名"
              name="username"
              rules={[{ required: true, message: '请输入用户名!' }]}
            >
              <Input placeholder="请输入用户名" />
            </Form.Item>

            <Form.Item
              label="密码"
              name="password"
              rules={[{ required: true, message: '请输入密码!' }]}
            >
              <Input.Password placeholder="请输入密码" />
            </Form.Item>

            <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
              <Button type="primary" htmlType="submit">
                Submit
              </Button>
            </Form.Item>
          </Form>
        </div>
      </div>
    )
  }
}